<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %> 
<!DOCTYPE html>
<html>
<head>
    <title>已添加药品</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>

    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>已添加药品</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="proProjList.jsp">采购项目</a></li>
            <li class="active"><a href="#">已添加药品</a></li>
        </ol>
    </section>
     <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                    <!-- <div class="form-group form-group-xs">
                     <label>药品编码：</label>
                        <input class="form-control" type="text" id="sdrugCode" placeholder="药品编码" />
                    </div>
                     <div class="form-group form-group-xs">
                        <label>通用名：</label>
                        <input class="form-control" type="text" id="sdrugName" placeholder="通用名" />
                    </div>
                    <div class="form-group form-group-xs">
                        <label>生产企业：</label>
                        <input class="form-control" type="text" id="sdrugComp" placeholder="生产企业" />
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="txtDrugForm">是否国家基药:</label>
                        <select class="form-control"  id="sbaseDrug" name="status">
                            <option selected="selected" value="">请选择</option>
                            <option  value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="txtDrugForm">是否低价药:</label>
                        <select class="form-control"  id="slowDrug" name="status">
                            <option selected="selected" value="">请选择</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="txtDrugForm">状态:</label>
                        <select class="form-control"  id="status" name="status">
                            <option selected="selected" value="">请选择</option>
                            <option value="1">启用</option>
                            <option value="0">停用</option>
                        </select>
                    </div>
                    <button type="button" class="btn btn-success btn-sm" onclick="search()">查  询</button> -->
                    
                    
                    <div class="input">
                        <div class="textalign1">通用名：</div>
                        <div class="boxinput">
                            <input type="text" class="textinput" id="sdrugName" name="sdrugName" placeholder="通用名" />
                        </div>
                        
                        <div class="textalign1">药品编码：</div>
                        <div class="boxinput">
                            <input type="text" class="textinput" id="sdrugCode" name="sdrugCode" placeholder="药品编码" />
                        </div>

                       <div class="textalign1">生产企业：</div>
                        <div class="boxinput">
                            <input type="text" class="textinput" id="sdrugComp" name="sdrugComp" placeholder="生产企业" />
                        </div> 
                   </div>
                   
                    <div class="input">
                        <div class="textalign1">是否国家基药：</div>
                        <div class="boxinput">
                            <select id="sbaseDrug" name="status" class="textinput">
                                <option  value="">请选择</option>
                                <option  value="1">是</option>
                                <option  value="0">否</option>
                            </select>
                        </div>
                        
                        <div class="textalign1">是否低价药：</div>
                        <div class="boxinput">
                            <select id="slowDrug" name="status" class="textinput">
                                <option  value="">请选择</option>
                                <option  value="1">是</option>
                                <option  value="0">否</option>
                            </select>
                        </div>
                        
                        <div class="textalign1">状态：</div>
                        <div class="boxinput">
                            <select id="status" name="status" class="textinput">
                                <option  value="">请选择</option>
                                <option  value="1">启用</option>
                                <option  value="0">停用</option>
                            </select>
                        </div>
                        
                        <div class="textalign" >
                            <button  id="selectSerch"  type="button" onclick="search();" class="btn btn-success btn-sm"> <spring:message code="message.button.seachSpacing"/> </button>
                        </div>
                   </div>
                    
                    
                    
                </div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
             <label  class="btn btn-default btn-sm" onclick="batchChangeStatus(0)">停 用</label>
             <label class="btn btn-default btn-sm" onclick="batchChangeStatus(1)">启 用</label>
             <a href="toPurList.html" class="btn btn-default btn-sm" >返&nbsp;回</a>
        </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    function search() {
        var sdrugCode = $.trim($("#sdrugCode").val());
        var sdrugName = $.trim($("#sdrugName").val());
        var sdrugComp = $.trim($("#sdrugComp").val());
        var sbaseDrug = $("#sbaseDrug").val();
        var slowDrug = $("#slowDrug").val();
        var status = $("#status").val();
        $("#gridlist").jqGrid("clearGridData");
            $("#gridlist").jqGrid('setGridParam',{ 
            datatype:'json',
            postData:{"sdrugCode":sdrugCode, "sdrugName":sdrugName, "sdrugComp":sdrugComp, "sbaseDrug":sbaseDrug, "slowDrug":slowDrug,"status":status},
            page :  1
        }).trigger("reloadGrid"); //重新载入  
    }
        $(function () {
        	
        	 //加载页面光标在名字框内，位于第一个
        	   $("#sdrugName").focus();
        	   
        	 //绑定回车     id="selectSerch"   
        	   $('#sdrugName,#sdrugCode,#sdrugComp,#sbaseDrug,#slowDrug,#status').bind('keydown', function(event) {
        	       if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
        	           $('#selectSerch').click();
        	       }
        	   }); 
            
            $("#gridlist").jqGrid({
                url: "getAddedBidPurProjectDrugListJson.html",
                mtype: "POST",
                postData: { "projId" : "${projId}"},
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: [
                         
                           'projDrugId',
                           '药品编码', 
                           '通用名',
                           '剂型',
                           '规格',
                           '转换系数',
                           '单位',
                           '材质',
                           '生产企业',
                           '国家基药',
                           '低价药',
                           '状态'
                          
                           ],
                colModel: [
                    
                    { name: 'projDrugId',hidden:true, width: 10, align:"center", sortable: false},
                    { name: 'drugCode', width: 60 , align:"center",sortable: false,
                    	formatter:function(val, opts, row) {
                            return "<a href=\"javascript:showDrugInfo('"+val+"')\">"+val+"</a>"
                           }
                    },
                    { name: 'drugName', width: 120 , align:"center" ,sortable: false},
                    { name: 'formName', width: 40 , align:"center" ,sortable: false},
                    { name: 'specName', width: 40 , align:"center" ,sortable: false},
                    { name: 'factor', width: 40 , align:"center" ,sortable: false},
                    { name: 'unit', width: 40 , align:"center" ,sortable: false},
                    { name: 'materialName', width: 40 , align:"center" ,sortable: false},
                    {name : 'compName',width :80,align : "center",
                    	 formatter:function(val, opts,row) {
                             return "<a href='javascript:showCompInfo(\"" + row.compCode + "\", \"" + val + "\");'>"+val+"</a>"
                        }
					},
                    { name: 'drugAttr', width: 40 , align:"center" ,sortable: false,formatter:function(cellvalue, options, row){if(cellvalue==1){ return "国家基药（2012）"; }else if(cellvalue==2){ return "省增补"; }else if(cellvalue==3){ return "其它"; }else{ return "非基药"; }}},
                    { name: 'isLowprice', width: 40 , align:"center" ,sortable: false,formatter:function(cellvalue, options, row){if(cellvalue==1){ return "是"; }else if(cellvalue==0){ return "否"; }else{return "未知"}}},         
                    { name: 'statusText', width: 40 , align:"center" ,sortable: false}
                   
                ],
                
                rowNum: 10,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "${projName}-已添加药品 ",
                //序号宽度自动变化
                gridComplete:function(){
                    //序号列宽度自适应（参数为jqgridID）
                    autoRNWidth("gridlist");
                    //数据只有一条时默认选中（参数为jqgridID）
                    selectByOneData("gridlist");
                },
                jsonReader: {
                    repeatitems: false,
                    id: "drugId"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });


        function batchSubmitDrugTOProj(){
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];

            if (rowIds.length <= 0) {
                $.HN.message.alert("请选择要操作的行！", "消息", "error");
                return;
            }
            var list = [];
            for (var i=0; i<rowIds.length; i++) {
                rowId = rowIds[i];
                list.push({"drugId":rowId,"projId":'${bidProject.projId}'});
            }
            submitDrugTOProj(JSON.stringify(list));
        }
        
        
        
        function submitDrugTOProj(list){
            $.ajax({
                type:"POST",
                url:"batchSubmitDrugTOProj.html",
                data:{"drugs":list},
                dataType:"json",
                success:function(returnData){
                    if (returnData.success == true) {
                        $("#gridlist").jqGrid("clearGridData");
                        $("#gridlist").jqGrid().trigger("reloadGrid");
                        $.HN.message.alert("添加药品成功！", "消息", "success");
                    } else {
                        $.HN.message.alert("添加药品失败！", "消息", "error");
                    }
                }
            });
            
        }
        
         function changeStatus(id, status) {
            //启用禁用
            $.ajax({
            	 type:"POST",
                 url:"${ctx}/bidOtherProject/changeStatus.html",
                 data:{"projDrugId":id,"status":status},
                 dataType:"json",
                 success: function(result) {
                     if (result) {
                         $.HN.message.alert("保存成功！", "消息", "success");
                     	$("#gridlist").jqGrid('setGridParam',{  
                	        datatype:'json'
                	    }).trigger("reloadGrid");
                     } else {
                         $.HN.message.alert("保存失败！", "消息", "error");
                     }
                 }
            });
        } 
        
         function batchChangeStatus(status) {
             var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
             if (rowIds.length <= 0) {
                 $.HN.message.alert("请选择要操作的行！", "消息", "error");
                 return;
             }
             var list = [];
             for (var i=0; i<rowIds.length; i++) {
            	 var rowdata = $("#gridlist").jqGrid(
							'getRowData', rowIds[i]);
                 rowId = rowdata.projDrugId;
                 list.push({"projDrugId":rowId, "status":status});
             }
             $.post("batchChangeStatus.html", {
                 "array" : json.jsonToString(list)
             }, function(result) {
                 if (result) {
                     $.HN.message.alert("操作成功！", "消息", "success");
                     $("#gridlist").jqGrid('setGridParam',{  
             	        datatype:'json'
             	    }).trigger("reloadGrid");
                 } else {
                     $.HN.message.alert("操作失败！", "消息", "error");
                 }
             }, "json")
         }

         
    </script>
</body>
</html>